package org.kealinghornets.jchuah.buttons;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void checkVictory() {
        View leftstar=(findViewById(R.id.Left_star));
        View midstar=(findViewById(R.id.Middle_star));
        View rightstar=(findViewById(R.id.Right_star));
        if (leftstar.getVisibility() == View.INVISIBLE && midstar.getVisibility() == View.INVISIBLE && rightstar.getVisibility() == View.INVISIBLE) {
            Log.d("u1","u2");
            Toast.makeText(this, "U1", Toast.LENGTH_SHORT).show();
            startActivity(new Intent(this, Level_2_Activity.class));
        }
    }

    public void toggleVisibility(int id){
        View star;
        star = findViewById(id);
        if(star.getVisibility()==View.VISIBLE){
            star.setVisibility(View.INVISIBLE);
        }
        else{
            star.setVisibility(View.VISIBLE);
        }
    }

    public void onLeft_buttonPush(View view){
        Log.d("left","");
        toggleVisibility(R.id.Left_star);
        toggleVisibility(R.id.Right_star);
        Toast.makeText(this, "Left", Toast.LENGTH_SHORT).show();
        checkVictory();
    }

    public void onMiddle_buttonPush(View view){
        Log.d("middle","");
        toggleVisibility(R.id.Middle_star);
        Toast.makeText(this, "Middle", Toast.LENGTH_SHORT).show();
        checkVictory();
    }

    public void onRight_buttonPush(View view){
        Log.d("right","");
        toggleVisibility(R.id.Middle_star);
        toggleVisibility(R.id.Right_star);
        Toast.makeText(this, "Right", Toast.LENGTH_SHORT).show();
        checkVictory();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        if (id == R.id.action_Level_1) {
            startActivity(new Intent(this, MainActivity.class));
        }

        if (id == R.id.action_Level_2) {
            startActivity(new Intent(this, Level_2_Activity.class));
        }

        if (id == R.id.action_Level_3) {
            startActivity(new Intent(this, Level_3_Activity.class));
        }

        return super.onOptionsItemSelected(item);
    }
}
